package com.wing.cabinet.model.entity;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 刀具编号
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("cab_knife_life_detail")
public class KnifeLifeDetail extends BaseEntity<KnifeLifeDetail> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
    * 存入时间
    */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime inTime;

    /**
    * 取出时间
    */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime outTime;

    /**
     * 当前可用时长
     */
    private Integer preTime;

    /**
     * 使用时长
     */
    private Integer lifeTime;

    /**
     * 剩余时长
     */
    private Integer remainingTime;

    /**
     * 在用流水id
     */
    private Long useInId;

    /**
     * 在用流水id
     */
    private Long useOutId;

    /**
     * 刀具条码
     */
    private String labelCode;


    private Integer useTime;



    private Long inCreator;

    private Long outCreator;

    private String inCreatorName;

    private String outCreatorName;


    private InBusinessType inBusinessType;

    private OutBusinessType outBusinessType;

    public enum InBusinessType implements IEnum<Integer> {

        /**
         * 业务类型:cellCabReceive(1,售刀柜领取);repairOrderSign(2,维修订单签收)
         */
        cellCabOut(1,"售刀柜领新"),

        tempIn(2,"存入暂存柜"),
        /**
         * 领取
         */
        repairOrderSign(3,"维修订单签收"),

        tempOut(4,"暂存柜取出"),

        outByReturned(5,"归还仓库管理员"),

        cellCabOutByOldNew(6,"售刀柜领新(以旧换新)"),

        /**
         * 维修
         */
        repairIn(7,"维修存入"),
        /**
         * 回收
         */
        recycleIn(8,"报废存入"),


        repairOutByCheck(9,"盘验维修取出"),

        recycleOutByCheck(10,"盘验报废取出"),

        recycleInByOldNew(11,"以旧换新存入报废"),

        tempInByCheck(12,"盘验暂存存入"),

        tempOutByCheck(13,"盘验暂存取出"),
        tempOutByCheckLose(14,"盘验暂存缺失"),

        repairOutByCheckLose(15,"盘验维修缺失"),

        recycleOutByCheckLose(16,"盘验报废缺失"),

        tempInByOldNew(17,"以旧换新存入暂存"),

        repairInByOldNew(18,"以旧换新存入维修"),

        tempOutByCheckSpec(19,"盘验暂存产品规格不相符"),

        repairOutByCheckSpec(20,"盘验维修产品规格不相符"),

        recycleOutByCheckSpec(21,"盘验报废产品规格不相符"),

        importUseByExcel(22,"导入在用刀具"),

        loss(31,"报失");




        private int code;
        private String desc;

        InBusinessType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static InBusinessType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (InBusinessType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    public enum OutBusinessType implements IEnum<Integer> {

        /**
         * 业务类型:cellCabReceive(1,售刀柜领取);repairOrderSign(2,维修订单签收)
         */
        cellCabOut(1,"售刀柜领新"),

        tempIn(2,"存入暂存柜"),
        /**
         * 领取
         */
        repairOrderSign(3,"维修订单签收"),

        tempOut(4,"暂存柜取出"),

        outByReturned(5,"归还仓库管理员"),

        cellCabOutByOldNew(6,"售刀柜领新(以旧换新)"),

        /**
         * 维修
         */
        repairIn(7,"维修存入"),
        /**
         * 回收
         */
        recycleIn(8,"报废存入"),


        repairOutByCheck(9,"盘验维修取出"),

        recycleOutByCheck(10,"盘验报废取出"),

        recycleInByOldNew(11,"以旧换新存入报废"),

        tempInByCheck(12,"盘验暂存存入"),

        tempOutByCheck(13,"盘验暂存取出"),
        tempOutByCheckLose(14,"盘验暂存缺失"),

        repairOutByCheckLose(15,"盘验维修缺失"),

        recycleOutByCheckLose(16,"盘验报废缺失"),

        tempInByOldNew(17,"以旧换新存入暂存"),

        repairInByOldNew(18,"以旧换新存入维修"),

        tempOutByCheckSpec(19,"盘验暂存产品规格不相符"),

        repairOutByCheckSpec(20,"盘验维修产品规格不相符"),

        recycleOutByCheckSpec(21,"盘验报废产品规格不相符"),

        importUseByExcel(22,"导入在用刀具"),

        loss(31,"报失");




        private int code;
        private String desc;

        OutBusinessType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static OutBusinessType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (OutBusinessType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    private String skuCode;

    private String productCode;

    private Long brandId;

    @TableField(exist = false)
    private String inBusinessTypeDesc;

    public String getInBusinessTypeDesc(){
        if (this.inBusinessType!=null){
            return this.inBusinessType.getDesc();
        }
        return "";
    }

    private String enterpriseCode;

    private LifeUnit lifeUnit;

    public enum LifeUnit implements IEnum<Integer> {

        /**
         * 分钟
         */
        minute(1,"分钟"),
        /**
         * 个数
         */
        number(2,"个数");

        private int code;
        private String desc;

        LifeUnit(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static LifeUnit jsonCreator(String name) {
            if (org.apache.commons.lang.StringUtils.isNotBlank(name)) {
                for (LifeUnit item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }
}
